home *** CD-ROM | disk | FTP | other *** search
/ Chip: Chipnet / CHIPNET Aralık 1997.iso / linux / redhat / misc / src / install / windows.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-11  |  2.1 KB  |  103 lines

  1. #include <errno.h>
  2. #include <newt.h>
  3. #include <stdarg.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7.  
  8. #include "perror.h"
  9. #include "windows.h"
  10.  
  11. /* this makes no attempt to look nice */
  12. static void vwindow(int left, int top, int width, int height, char * title, 
  13.             char * message, va_list args) {
  14.     newtComponent b1, t, f;
  15.     char * buf = NULL;
  16.     int size = 0;
  17.     int i = 0;
  18.  
  19.     do {
  20.     size += 1000;
  21.     if (buf) free(buf);
  22.     buf = malloc(size);
  23.     i = vsnprintf(buf, size, message, args);
  24.     } while (i == size);
  25.  
  26.     newtOpenWindow(left, top, width, height, title);
  27.  
  28.     b1 = newtButton((width - 8) / 2, height - 4, "Ok");
  29.     t = newtTextbox(1, 1, width - 2, height - 5, NEWT_TEXTBOX_WRAP);
  30.     newtTextboxSetText(t, buf);
  31.     f = newtForm(NULL, NULL, 0);
  32.  
  33.     free(buf);
  34.  
  35.     newtFormAddComponents(f, t, b1, NULL);
  36.  
  37.     newtRunForm(f);
  38.  
  39.     newtFormDestroy(f);
  40.     newtPopWindow();
  41. }
  42.  
  43. void winMessage(int left, int top, int width, int height, char * title,
  44.         char * message, ...) {
  45.     va_list args;
  46.  
  47.     va_start(args, message);
  48.     vwindow(left, top, width, height, title, message, args);
  49.     va_end(args);
  50. }
  51.  
  52. void messageWindow(char * title, char * message, ...) {
  53.     va_list args;
  54.  
  55.     va_start(args, message);
  56.     vwindow(17, 4, 45, 15, title, message, args);
  57.     va_end(args);
  58. }
  59.  
  60. void errorWindow(char * str) {
  61.     char * a;
  62.  
  63.     a = alloca(strlen(str) + 5);
  64.     strcpy(a, str);
  65.     strcat(a, ": %s");
  66.  
  67.     messageWindow("Error", str, strerror(errno));
  68. }
  69.  
  70. void winStatus(int width, int height, char * title,
  71.         char * text, ...) {
  72.     newtComponent t, f;
  73.     char * buf = NULL;
  74.     int size = 0;
  75.     int i = 0;
  76.     va_list args;
  77.  
  78.     va_start(args, text);
  79.  
  80.     do {
  81.     size += 1000;
  82.     if (buf) free(buf);
  83.     buf = malloc(size);
  84.     i = vsnprintf(buf, size, text, args);
  85.     } while (i == size);
  86.  
  87.     va_end(args);
  88.  
  89.     newtOpenWindow(40 - (width / 2), 11 - (height / 2), width, height, title);
  90.  
  91.     t = newtTextbox(1, 1, width - 2, height - 2, NEWT_TEXTBOX_WRAP);
  92.     newtTextboxSetText(t, buf);
  93.     f = newtForm(NULL, NULL, 0);
  94.  
  95.     free(buf);
  96.  
  97.     newtFormAddComponent(f, t);
  98.  
  99.     newtDrawForm(f);
  100.     newtRefresh();
  101.     newtFormDestroy(f);
  102. }
  103.